package xyz.yuzegod.megawalls.effect;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import xyz.yuzegod.megawalls.classes.Upgradeable;
import xyz.yuzegod.megawalls.game.GamePlayer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class KillMessage implements Upgradeable
{
    public static final KillMessage DEFAULT;
    private String name;
    private String displayName;
    private int price;
    private Map<String, String> messages;
    
    public KillMessage(final String name, final String displayName, final int price, final Map<String, String> messages) {
        this.name = name;
        this.displayName = displayName;
        this.price = price;
        this.messages = messages;
    }
    
    public String getMessage(final String cause) {
        return this.messages.getOrDefault(cause, "被击杀");
    }
    
    @Override
    public int maxedLevel() {
        return 0;
    }
    
    @Override
    public double getAttribute(final int level) {
        return 0.0;
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> list = new ArrayList<String>();
        list.add("§7解锁§c" + this.displayName + "§7击杀信息。");
        list.add(" ");
        for (final String message : this.messages.values()) {
            list.add("§e玩家 §f" + message + ",击杀者: §e你");
        }
        return list;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        gamePlayer.getPlayerStats().getEffectStats().updateKillMessage(this.name);
        Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "lp user " + gamePlayer.getName() + " permission set MegaWalls.killmessage." + this.name);
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return 0;
    }
    
    @Override
    public Material getIconType() {
        return Material.PAPER;
    }
    
    @Override
    public byte getIconData() {
        return 0;
    }
    
    @Override
    public int getCost(final int level) {
        return this.price;
    }
    
    @Override
    public String getName() {
        return this.name;
    }
    
    public String getDisplayName() {
        return this.displayName;
    }
    
    public int getPrice() {
        return this.price;
    }
    
    static {
        final Map<String, String> messages = new HashMap<String, String>();
        messages.put("Arrow", "被射杀");
        messages.put("Snowball", "被雪球砸死");
        messages.put("Attack", "被击杀");
        messages.put("Poison", "被毒药杀死");
        messages.put("Explode", "被炸死");
        messages.put("Magic", "被魔法杀死");
        DEFAULT = new KillMessage("Default", "默认", 0, messages);
    }
}
